<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function(Request $request) {
    return $request->user();
});

// Route::get('articles', 'ArticleController@index');
// Route::get('articles/{id}', 'ArticleController@show');
// Route::post('articles', 'ArticleController@store');
// Route::put('articles/{id}', 'ArticleController@update');
// Route::delete('articles/{id}', 'ArticleController@delete');


// Route::post('login', 'Auth\LoginController@login');
// Route::middleware('auth:api')->post('logout', 'Auth\LoginController@logout');
// Route::post('register', 'Auth\RegisterController@register');
//
// Route::middleware('auth:api')
//     ->get('/user', function(Request $request) {
//         return $request->user();
//     });

Route::group(['middleware' => 'auth:api'], function() {
    Route::get('articles', 'ArticleController@index');
    Route::get('articles/{article}', 'ArticleController@show');
    Route::post('articles', 'ArticleController@store');
    Route::put('articles/{article}', 'ArticleController@update');
    Route::delete('articles/{article}', 'ArticleController@delete');
});

/**
 * jwt 相关
 */
Route::group([

    'prefix' => 'user'

], function($router) {

    Route::any('login', 'AuthController@login');
    Route::any('logout', 'AuthController@logout');
    Route::any('refresh', 'AuthController@refresh');
    Route::any('me', 'AuthController@me');

});

Route::group(['prefix' => 'admin'], function($router) {

    Route::any('login', 'AuthController@adminLogin')->middleware('admin.login');
    Route::post('logout', 'AuthController@logout');
    Route::post('refresh', 'AuthController@refresh');
    Route::any('me', 'AuthController@me');

});

Route::group(['domain' => 'admin.example.com', 'namespace' => 'Admin'], function () {
    // 之前将默认认证相关类保持结构复制到了 Admin 下，此时只需简单指定公共命名空间即可
    Route::auth(); // 各种注册、登录、找回密码的默认路由
    Route::group(['middleware' => ['auth:admins']], function () { // 指定 auth 的 guard 为 新建的 admins
        Route::get('/', 'HomeController@index'); // 登录成功才能访问的部分放在认证保护内
    });
});

